#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "debug_printf.h"
#include "node.h"
#include "event.h"

extern Node *node;

void mouse(int button, int x, int y ) {


}

void keyboard(unsigned char key, int x, int y) {
	D("%c\n", key);
	switch(key) {
		case 27:
			glutSetKeyRepeat(GLUT_KEY_REPEAT_DEFAULT);
			exit(0);
		break;
		case 'w':
			node->cam[2] -= 10;
			if(node->cam[2] <= -2500)
				node->cam[2] = -2500;
			glLoadIdentity();
			gluLookAt(node->cam[0], node->cam[1], node->cam[2],
				node->view_point[0], node->view_point[1], node->view_point[2],
				0, 1, 0);
		break;
		case 's':
			node->cam[2] += 10;
			if(node->cam[2] >= 2500)
				node->cam[2] = 2500;
			glLoadIdentity();
			gluLookAt(node->cam[0], node->cam[1], node->cam[2],
				node->view_point[0], node->view_point[1], node->view_point[2],
				0, 1, 0);
		break;
		case 'a':
			node->cam[0] -= 10;
			node->view_point[0] -= 10;
			glLoadIdentity();
			gluLookAt(node->cam[0], node->cam[1], node->cam[2],
				node->view_point[0], node->view_point[1], node->view_point[2],
				0, 1, 0);
		break;
		case 'd':
			node->cam[0] += 10;
			node->view_point[0] += 10;
			glLoadIdentity();
			gluLookAt(node->cam[0], node->cam[1], node->cam[2],
				node->view_point[0], node->view_point[1], node->view_point[2],
				0, 1, 0);
	}
}

void mainMenuFunc(int v) {
	switch(v) {
		case 1:
			node->frot = !node->frot;
			D("Entrei %s\n", __FUNCTION__);
		break;
		case 2:
			glLoadIdentity();
			node->cam[0] = node->cam[1] = 0;
			gluLookAt(node->cam[0], node->cam[1], node->cam[2],
				node->view_point[0], node->view_point[1], node->view_point[2],
				0, 1, 0);
		break;
		case 3:
			glLoadIdentity();
			node->cam[0] = node->cam[1] = 300;
			gluLookAt(node->cam[0], node->cam[1], node->cam[2],
				node->view_point[0], node->view_point[1], node->view_point[2],
				0, 1, 0);
		break;
		case 4:
			glLoadIdentity();
			node->cam[0] = 300;
			node->cam[1] = -300;
			gluLookAt(node->cam[0], node->cam[1], node->cam[2],
				node->view_point[0], node->view_point[1], node->view_point[2],
				0, 1, 0);
		break;
		case 5:
			glLoadIdentity();
			node->cam[0] = 0;
			node->cam[1] = 0;
			node->cam[2] = 1000;
			node->view_point[0] = node->view_point[1] = node->view_point[2] = 0;
			gluLookAt(node->cam[0], node->cam[1], node->cam[2],
				node->view_point[0], node->view_point[1], node->view_point[2],
				0, 1, 0);

		break;
		case 6:
			exit(0);
	}
}

void subMenuFunc(int v) {
	if(v == 1);
	else
		node->fval_allocated = !node->fval_allocated;
}


